<?php

namespace App\Task;

use App\Model\Device;
use Hyperf\Crontab\Annotation\Crontab;

//#[Crontab(rule: "* * * * *", name: "DeviceNotOnlineTask", callback: "execute", memo: "定时处理不在线的设备")]
class DeviceNotOnlineTask
{
    public function execute(): void
    {
        // 大于三分钟设置离线
        $min = 60;// 三分钟
        $curr_time = date('Y-m-d H:i:s');
        $decr_time = strtotime($curr_time . "-{$min} minute");
        $time = date('Y-m-d H:i:s', $decr_time);
        Device::where('inline', Device::ONLINE)
            ->where('last_online_at', '<', $time)
            ->update(['inline' => Device::NOT_ONLINE, 'fd' => null]);
    }
}